{include file="public/header"}

<body>
    <div class="layui-fluid">
        <div class="layui-card-body" pad15>
            <div class="layui-form" lay-filter="">
                <form action="" method="post" class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <label for="name" class="layui-form-label">
                            账号
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="username" name="username" value="{$admin.username}" required=""
                                lay-verify="required" autocomplete="off" class="layui-input" readonly disabled>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="name" class="layui-form-label">
                            备注
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="name" name="nickname" value="{$admin.nickname|default=''}"
                                required="" lay-verify="required" autocomplete="off" class="layui-input" readonly
                                disabled>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="name" class="layui-form-label">
                            发帖备注
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="poster" name="poster" value="{$admin.poster|default=''}" required=""
                                lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="cover" class="layui-form-label">
                            头像</label>
                        <div class="layui-input-inline">
                            <button type="button" class="layui-btn" id="test1">上传头像</button>
                            <div class="layui-upload-list">
                                <input type="hidden" value="{$admin.images|default=''}" name="images" id="covers">
                                <img class="layui-upload-img" id="demo1" src="{$admin.images|default=''}"
                                    style="width: 200px;height: auto;">
                            </div>
                            <div class="layui-progress layui-progress-big" lay-showpercent="true"
                                lay-filter="component-progress-demo">
                                <div class="layui-progress-bar layui-bg-red" lay-percent="0%"></div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="name" class="layui-form-label">
                            密码
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="password" name="password" value="" autocomplete="off"
                                class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="name" class="layui-form-label">
                            确认密码
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="passworder" name="passworder" value="" autocomplete="off"
                                class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="add">确认修改</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    {include file="public/footer"}

    <script>
        layui.use(['form', 'layer', 'upload'], function () {
            $ = layui.jquery;
            var form = layui.form
                , upload = layui.upload
                , element = layui.element
                , layer = layui.layer;
            //图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                , url: '/base/upload_img'
                , accept: 'images'
                , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                    layer.load(); //上传loading
                }, progress: function (n, elem, res, index) {
                    element.progress('component-progress-demo', n + '%');
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.status == 1) {
                        layer.closeAll('loading'); //关闭loading
                        return layer.msg('图片上传失败，请重试');
                    }
                    if (res.status == 0) {
                        //上传成功
                        $('#demo1').attr('src', res.data.src); //图片链接（base64）
                        $('#covers').val(res.data.src);
                        layer.closeAll('loading'); //关闭loading
                        return layer.msg('图片上传成功');
                    }
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                    layer.closeAll('loading'); //关闭loading
                }
            });
            //监听提交
            form.on('submit(add)', function (data) {
                console.log(data);
                //发异步，把数据提交给php
                $.ajax({
                    'type': 'post',
                    data: data.field,
                    success: function (res) {
                        console.log(res);
                        if (res.status == 0) {
                            layer.msg(res.msg, { icon: 6, time: 1000 }, function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, time: 1000 });
                        }
                    }
                });
                return false;
            });

        });
    </script>